package com.lss.cloud.controller;

import com.lss.cloud.service.FlowLimiterService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * 2024/3/20-20:18
 * 功能:
 */
@RestController
@Slf4j
public class FlowLimiterController {
    ThreadLocal threadLocal;

    public ThreadLocal getThreadLocal() {
        return new ThreadLocal();
    }

    @GetMapping("/testA")
    public String testA()
    {
        return "------testA";
    }

    @GetMapping("/testB")
    public String testB()
    {
        return "------testB";
    }
    @Resource
    private FlowLimiterService flowLimiterService;
    @GetMapping("/testC")
    public String testC()
    {   flowLimiterService.common();
        return "------testC";
    }

    @GetMapping("/testD")
    public String testD()
    {    flowLimiterService.common();
        return "------testD";
    }

    @GetMapping("/testE")
    public String testE()
    {    flowLimiterService.common();
        System.out.println(System.currentTimeMillis());
        return "------testE";
    }
    @GetMapping("/testF")
    public String testF()
    {
        //暂停几秒钟线程
        try { TimeUnit.SECONDS.sleep(1); }
        catch (InterruptedException e) { e.printStackTrace(); }
        System.out.println("----测试:新增熔断规则-慢调用比例 ");
        return "------testF 新增熔断规则-慢调用比例";
    }
    @GetMapping("/testG")
    public String testG()
    {
        System.out.println("----测试:新增熔断规则-异常比例 ");
        int age = 10/0;
        return "------testG,新增熔断规则-异常比例 ";
    }


}
